import os

import pygame

import globalvars


class TropicalEnemy(pygame.sprite.Sprite):
	"""The base enemy class"""
	def __init__(self, position):
		pygame.sprite.Sprite.__init__(self) # Initialize base class			
		spriteFile = os.path.join('data', self.spriteName)
		self.image = pygame.image.load(spriteFile).convert_alpha()
		self.rect = self.image.get_rect()
		self.rect.bottomleft = position
		#self.temperature = 6 # This animal is warm.
		self.hasMoved = True

	def update(self):
		if self.temperature > 2 or self.hasMoved == False:
			self.rect.move_ip(0, 1)
			self.hasMoved = True
		else:
			self.hasMoved = False
		for projectile in pygame.sprite.spritecollide(self, globalvars.objects_arctic_projectiles, False):
			projectile.hit(self)
		if self.rect.top > globalvars.resolution[1] or self.rect.left > globalvars.resolution[0]:
			self.kill()

	def hit(self, projectile):
		self.temperature += projectile.temperature
		if self.temperature < 0:
			self.kill()
			globalvars.number_of_tuxs += self.value

